"""
  模块描述：超级短信模块报告接收-参数
  @author 8522
  @date 2022-05-17 17:57:38
  版权所有 Copyright www.dahantc.com
"""
from common.util import EntityUtil


# 审核报告参数
class ExamineReport:
    # 上传时素材的模板ID
    mmsProductId = ""
    # 该批短信提交结果；说明请参照：超级短信提交响应错误码
    code = ""
    # 响应消息说明
    msg = ""
    # 审核通过或未通过原因、备注
    auditMemo = ""

    def __init__(self, mmsProductId, code, msg, auditMemo):
        self.mmsProductId = mmsProductId
        self.code = code
        self.msg = msg
        self.auditMemo = auditMemo

    # class转字典
    def parseDict(self):
        return self.__dict__

    # 将字典转换成class
    @staticmethod
    def parseObj(val):
        if type(val) != dict:
            raise Exception("val参数必须为字典类型")
        return ExamineReport(EntityUtil.getValue(val, "mmsProductId"), EntityUtil.getValue(val, "code"),
                             EntityUtil.getValue(val, "msg"), EntityUtil.getValue(val, "auditMemo"))


# 审核报告接收-参数
class ExamineReportReceiveParam:
    # 结果代码
    result = ""
    # 结果描述
    desc = ""
    # 报告集合
    # 类型：List<ExamineReport>
    reports = []

    def __init__(self, result, desc, reports):
        self.result = result
        self.desc = desc
        self.reports = reports

    # class转字典
    def parseDict(self):
        temp = self.reports
        res = {"result": self.result, "desc": self.desc, "reports": []}
        for examineReport in temp:
            res["reports"].append(examineReport.parseDict())
        return res

    # 将字典转换成class
    @staticmethod
    def parseObj(val):
        if type(val) != dict:
            raise Exception("val参数必须为字典类型")
        res = ExamineReportReceiveParam(EntityUtil.getValue(val, "result"), EntityUtil.getValue(val, "desc"), [])
        if "reports" in val.keys():
            for examineReport in val["reports"]:
                res.reports.append(ExamineReport.parseObj(examineReport))
        return res


# 超级短信发送状态报告参数
class SendReport:
    # 批次id
    msgId = ""
    # 手机号码,对应请求包中的一个手机号码
    mobile = ""
    # 彩信发送结果：0—成功（如果配置了需要下载状态，status为0时errorCode为RECEIVD表示下载成功）；1—接口处理失败； 2—运营商网关失败
    status = ""
    # 当status为1时，可参考：处理失败错误码；当status为2时，表示运营商网关返回的原始值
    errorCode = ""
    # 错误码描述
    statusDesp = ""
    # 状态报告时间
    reportTime = ""

    def __init__(self, msgId, mobile, status, errorCode, statusDesp, reportTime):
        self.msgId = msgId
        self.mobile = mobile
        self.status = status
        self.errorCode = errorCode
        self.statusDesp = statusDesp
        self.reportTime = reportTime

    # class转字典
    def parseDict(self):
        return self.__dict__

    # 将字典转换成class
    @staticmethod
    def parseObj(val):
        if type(val) != dict:
            raise Exception("val参数必须为字典类型")
        return SendReport(EntityUtil.getValue(val, "msgId"), EntityUtil.getValue(val, "mobile"),
                          EntityUtil.getValue(val, "status"), EntityUtil.getValue(val, "errorCode"),
                          EntityUtil.getValue(val, "statusDesp"), EntityUtil.getValue(val, "reportTime"))


# 超级短信发送状态报告接收-参数
class SendReportReceiveParam:
    # 结果代码
    result = ""
    # 结果描述
    msg = ""
    # 状态报告集合
    # 类型：List<SendReport>
    reports = []

    def __init__(self, result, msg, reports):
        self.result = result
        self.msg = msg
        self.reports = reports

    # class转字典
    def parseDict(self):
        temp = self.reports
        res = {"result": self.result, "msg": self.msg, "reports": []}
        for sendReport in temp:
            res["reports"].append(sendReport.parseDict())
        return res

    # 将字典转换成class
    @staticmethod
    def parseObj(val):
        if type(val) != dict:
            raise Exception("val参数必须为字典类型")
        res = ExamineReportReceiveParam(EntityUtil.getValue(val, "result"), EntityUtil.getValue(val, "msg"), [])
        if "reports" in val.keys():
            for sendReport in val["reports"]:
                res.reports.append(SendReport.parseObj(sendReport))
        return res


# 审核报告接收-返参
class ExamineReportReceiveResponse:
    # 推送结果，成功时status的值返回success，其他值均认为推送失败。
    status = ""

    def __init__(self, status):
        self.status = status

    # class转字典
    def parseDict(self):
        return self.__dict__

    # 将字典转换成class
    @staticmethod
    def parseObj(val):
        if type(val) != dict:
            raise Exception("val参数必须为字典类型")
        return ExamineReportReceiveResponse(EntityUtil.getValue(val, "status"))


# 超级短信下发状态报告接收-返参
class SendReportReceiveResponse:
    # 推送结果，成功时status的值返回success，其他值均认为推送失败。
    status = ""

    def __init__(self, status):
        self.status = status

    # class转字典
    def parseDict(self):
        return self.__dict__

    # 将字典转换成class
    @staticmethod
    def parseObj(val):
        if type(val) != dict:
            raise Exception("val参数必须为字典类型")
        return SendReportReceiveResponse(EntityUtil.getValue(val, "status"))
